
function SelectPlus(options){
	this.options = options;
	if(!this.options.el){
		throw new Error("下拉框节点元素必传");
	}
	this.placeholder = this.options.data[0].text || "请选择";
	this.initDom();
}

SelectPlus.prototype.initDom = function(){
	var self = this;
	var jsb = document.createElement("div");
		jsb.className = "j-select-box";

	var checkbox = document.createElement("input");
		checkbox.className = "checkbox";
		checkbox.type = "checkbox";

	var jsr = document.createElement("div");
		jsr.className = "j-select-row";
	

	var jSelect = document.createElement("div");
		jSelect.className = "j-select";

	var input = document.createElement("input");
		input.type = "text";
		input.setAttribute("placeholder",this.placeholder);

	var ul = document.createElement("ul");
		ul.className = "j-select-option-box";
		function rendLi(data){
			ul.innerHTML = "";
			data.forEach(function(row,idx){
				let li = document.createElement("li");
					li.setAttribute("value",row.value);
					li.setAttribute("text",row.text);
					li.innerHTML = row.text;
					li.onclick = function(e){
						e.stopPropagation();
						$(this).addClass("active").siblings("li").removeClass("active");
						input.value = ($(this).attr("text") == self.placeholder?"":$(this).attr("text"));
						$(checkbox).prop("checked",false);
						self.options.done && self.options.done(row)
					}
					ul.appendChild(li);
			});
		}

		rendLi(this.options.data);

		jSelect.appendChild(input)
		jsr.appendChild(jSelect)
		jsr.appendChild(ul)
		jsb.appendChild(checkbox)
		jsb.appendChild(jsr)

		$(this.options.el).html(jsb);


		document.onclick = function(e){
			if(checkbox.checked && e.target.type!="checkbox"){
				$(checkbox).prop("checked",false);
			}
		}

		this.reload = function(data){
			rendLi(data)
		}
}



